package com.acme.bankapp.domain.bank;

public class CheckingAccount extends AbstractAccount {
	protected double overdraft;
	
	public CheckingAccount(double balance, double overdraft) {
		super(balance);
		this.overdraft = overdraft;
	}

	public void withdraw(double amount) throws OverdraftLimitExceededException {
		if (amount <= 0) {
			throw new IllegalArgumentException(MSG_AMOUNT_NONPOSITIVE);
		} else if (amount > this.balance + this.overdraft) {
			throw new OverdraftLimitExceededException(amount, getMaximumAmountToWithdraw());
		} else {
			balance -= amount;
		}

		assert (balance > -overdraft);
	}

	public double getMaximumAmountToWithdraw() {
		return balance + overdraft;
	}

}
